//
//  EditClassCoverImageCollectionViewCell.m
//  fitnessmanage
//
//  Created by wujian on 2017/11/30.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//

#import "EditClassCoverImageCollectionViewCell.h"

@implementation EditClassCoverImageCollectionViewCell

-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        UIImageView *courseImageView = [[UIImageView alloc] init];
        courseImageView.userInteractionEnabled = YES;
        courseImageView.layer.masksToBounds = YES;
        courseImageView.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:courseImageView];
        self.courseImageView = courseImageView;
        
        UIButton *delBtn = [[UIButton alloc] init];
        [delBtn setImage:@"courseshare_label_cancel"];
        [delBtn setHighlightedImage:@"courseshare_label_cancel"];
        [delBtn addTarget:self action:@selector(deleteBtnClick)];
        [courseImageView addSubview:delBtn];
        self.delBtn = delBtn;
        
        /**
         增加课程图片
         */
        UIImageView *addCourseImageView = [[UIImageView alloc] init];
        addCourseImageView.userInteractionEnabled = YES;
        addCourseImageView.layer.masksToBounds = YES;
        addCourseImageView.image = [UIImage imageNamed:@"icon_addimg"];
        addCourseImageView.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:addCourseImageView];
        self.addCourseImageView = addCourseImageView;
        
        [self setConstraints];
    }
    
    return self;
}

-(void)setConstraints{
    
    /**
     课程图片
     */
    [self.courseImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(self);
    }];
    
    [self.delBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.courseImageView).offset(3);
        make.right.mas_equalTo(self.courseImageView).offset(-3);
    }];
    
    /**
     添加图片
     */
    [self.addCourseImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.mas_equalTo(self);
    }];
}

-(void)deleteBtnClick{
    
    if ([self.deleteCoverImage respondsToSelector:@selector(deleteCoverImageWithRow:)]) {
        
        [self.deleteCoverImage deleteCoverImageWithRow:self.selectRow];
    }
}


-(void)setIsLast:(BOOL)isLast{
    
    if (isLast) {
        
        self.courseImageView.hidden = YES;
        self.delBtn.hidden = YES;
        self.addCourseImageView.hidden = NO;
    }
    else{
        
        self.courseImageView.hidden = NO;
        self.delBtn.hidden = NO;
        self.addCourseImageView.hidden = YES;
    }
}
@end
